import os, sys
import requests

sys.path.append(os.getcwd())
from common import settings

headers = {
    "content-length": '0',
    "sec-ch-ua-platform": '"Windows"',
    'accept': '*/*',
    'sec-fetch-dest': 'empty',
    "referer": "https://match.yuanrenxue.cn/match/3",
    "accept-encoding": "gzip, deflate, br, zstd",
    "accept-language": "zh-CN,zh;q=0.9",

}

headers1 = {
    # ":method": "POST",
    # ":authority": "match.yuanrenxue.cn",
    # ":scheme": "https",
    # ":path": "/jssm",
    "content-length": "0",
    "sec-ch-ua": '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
    "sec-ch-ua-mobile": "?0",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
    "sec-ch-ua-platform": '"Windows"',
    "accept": "*/*",
    "origin": "https://match.yuanrenxue.cn",
    "sec-fetch-site": "same-origin",
    "sec-fetch-mode": "cors",
    "sec-fetch-dest": "empty",
    "referer": "https://match.yuanrenxue.cn/match/3",
    "accept-encoding": "gzip, deflate, br, zstd",
    "accept-language": "zh-CN,zh;q=0.9",
    "cookie": "Hm_lvt_434c501fe98c1a8ec74b813751d4e3e3=1714036857; sessionid=dd2pk7pguwqfkl6568wp8lfuvnuv6s8a; qpfccr=true; Hm_lvt_9bcbda9cbf86757998a2339a0437208e=1714036830,1714381004,1714437986,1714464818; Hm_lvt_c99546cf032aaa5a679230de9a95c7db=1714380983,1714437986,1714456622,1714464818; Hm_lpvt_9bcbda9cbf86757998a2339a0437208e=1714464832; no-alert3=true; Hm_lpvt_c99546cf032aaa5a679230de9a95c7db=1714464871",
    "priority": "u=0, i"
}

session = requests.session()

# requests.session()
session.headers = headers


def pre():
    cookies = {'Cookie': 'sessionid=;'}

    response = session.post('https://match.yuanrenxue.cn/jssm',
                            verify=False,
                            cookies=cookies,
                            proxies=settings.proxies)
    print(response)
    print(response.cookies)
    for key, value in response.cookies.items():
        print(f"Key: {key}, Value: {value}")


def fetch(page):
    params = {
        'page': page,
    }

    response = session.get('https://match.yuanrenxue.cn/api/match/3',
                           params=params,
                           # cookies=cookies,
                           verify=False,
                           # headers=headers,
                           proxies=settings.proxies)

    return get_values(response.json()['data'])


def get_values(data: list) -> list:
    return [i['value'] for i in data]


if __name__ == '__main__':
    res: list = []
    for i in range(1, 6):
        pre()
        item = fetch(i)
        res.extend(item)
    print(res)
    print(max(res, key=lambda x: res.count(x)))
